<!DOCTYPE html>
<html lang="en">
	<head>
		<title>6图版全景图</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			* {
				margin: 0;
				padding: 0;
			}

			#rotateCtrl {
				position: absolute;
				top: 10px;
				right: 10px;
			}
		</style>
		<script src="./js/three.min.js"></script>
		<script src="./js/OrbitControls.js"></script>
		<script src="./js/jquery-3.2.1.min.js"></script>
	</head>
	<body>

		<div id="container"></div>
	</body>
	<script type="module">
		let container;

		let camera, scene, renderer;

		let pointLight;

		init();
		animate();

		function init() {
			container = document.createElement('div');
			document.body.appendChild(container);

			camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 5000);
			camera.target = new THREE.Vector3(0, 0, 0);


			scene = new THREE.Scene();



			//lights
			const ambient = new THREE.AmbientLight(0xffffff);
			scene.add(ambient);

			pointLight = new THREE.PointLight(0xffffff, 2);
			scene.add(pointLight);

			const geometry = new THREE.SphereGeometry(500, 60, 40);
			// invert the geometry on the x-axis so that all of the faces point inward
			geometry.scale(-1, 1, 1);

			const texture = new THREE.TextureLoader().load('img/test.jpg');
			const material = new THREE.MeshBasicMaterial({
				map: texture
			});

			const mesh = new THREE.Mesh(geometry, material);

			scene.add(mesh);

			//renderer
			renderer = new THREE.WebGLRenderer();
			renderer.setPixelRatio(window.devicePixelRatio);
			renderer.setSize(window.innerWidth, window.innerHeight);
			container.appendChild(renderer.domElement);

			//controls
			const controls = new THREE.OrbitControls(camera, renderer.domElement);
			controls.enableZoom = false;
			controls.enablePan = false;
			controls.minPolarAngle = Math.PI / 4;
			controls.maxPolarAngle = Math.PI / 1.5;


			window.addEventListener('resize', onWindowResize, false);

		}

		function onWindowResize() {

			camera.aspect = window.innerWidth / window.innerHeight;
			camera.updateProjectionMatrix();

			renderer.setSize(window.innerWidth, window.innerHeight);

		}

		function animate() {

			requestAnimationFrame(animate);
			render();

		}

		function render() {

			renderer.render(scene, camera);

		}
	</script>

</html>
